﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniFox.Data.MySql
{
    /// <summary>
    /// 
    /// </summary>
    public class MySqlDataCommand : DataCommand
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="cmdTxt"></param>
        /// <param name="cmdType"></param>
        /// <param name="database"></param>
        public MySqlDataCommand(string name, string cmdTxt, CommandType cmdType, Database database) : base(name, cmdTxt, cmdType, database)
        {

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="sortFields"></param>
        /// <returns></returns>
        protected override string CreateCommandTextForPagedQuery(int pageIndex, int pageSize, IDictionary<string, bool> sortFields)
        {
            string mainSql = this.CommandText;

            string sortStatement = DatabaseUtil.ResolveSortExpression(sortFields);
            string sql = $"{mainSql} {sortStatement} LIMIT {(pageIndex - 1) * pageSize}, {pageSize}";
            return sql;
        }
    }
}
